<?php

declare(strict_types=1);
/**
 * FastApp.
 * 9/22/24
 * @Author deepsea159
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Callback;


use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Callback\TelegramCallback;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;
use swoole\Coroutine;

#[Controller(prefix: "callback")]
class CallbackController extends ApiController
{
    #[Inject]
    public TelegramCallback $telegramCallback;

    #[PostMapping('tgbot/{id}')]
    public function tgbot(int $id): ResponseInterface
    {
        $data = $this->request->all();
        Coroutine::create(function () use ($id, $data) {
            try {
                $this->telegramCallback->tgbot($id, $data);
            } catch (\Throwable $throwable) {
                sys_notify('tgbot:' . $throwable->getMessage() . '|' . $throwable->getTraceAsString());
            }
        });
        return $this->success();
    }
}